#pragma once

#include <stdint.h>
#include <io/rttSerial.h>

namespace NXMFC
{

class fport
{
public:
    typedef enum 
    {
        FPRR_EFULL = -3,
        FPRR_EFM = -2,
        FPRR_EIO = -1,
        FPRR_CONTINUE = 0,
        FPRR_DONE
    }RecvResult;

public:
    fport();
    ~fport();

    bool allocBuf(int size = 32);
    RecvResult recv(NXMFC::rttSerial &iodev, int &type, int timeout_ms = 10);

    RecvResult putChar(uint8_t c);
    bool getChannel(unsigned chn, uint16_t &d, uint16_t *raw = 0);//chn:0~15

private:
    uint8_t checkSum(uint8_t *d, int len);

private:
    uint8_t *buf;
    uint8_t pos;
    uint8_t done;
    uint8_t escaped;
    uint8_t bufsz;
};

}
